package jmine.tec.json;

import java.io.IOException;
import java.io.Writer;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

/**
 * JSONBoolean implementado como enum
 * 
 * @author takeshi
 */
public enum JSONBoolean implements JSON {

    TRUE {
    },
    FALSE {
    };

    /**
     * Obtém a instância de JSONBoolean correspondente ao boolean dado
     * 
     * @param value value
     * @return JSONBoolean
     */
    public static JSONBoolean fromBoolean(boolean value) {
        return value ? TRUE : FALSE;
    }

    /**
     * {@inheritDoc}
     */
    public boolean booleanValue() {
        return this == TRUE;
    }

    /**
     * {@inheritDoc}
     */
    public Map<String, JSON> getAllProperties() {
        return Collections.emptyMap();
    }

    /**
     * {@inheritDoc}
     */
    public JSON getProperty(String propertyName) {
        return JSONNullObject.INSTANCE;
    }

    /**
     * {@inheritDoc}
     */
    public Collection<String> getPropertyNames() {
        return Collections.emptyList();
    }

    /**
     * {@inheritDoc}
     */
    public Collection<JSON> getPropertyValues() {
        return Collections.emptyList();
    }

    /**
     * {@inheritDoc}
     */
    public int getSize() {
        return 0;
    }

    /**
     * {@inheritDoc}
     */
    public void setProperty(String propertyName, JSON value) {
    }

    /**
     * {@inheritDoc}
     */
    public Object toJava() {
        return this.booleanValue();
    }

    /**
     * {@inheritDoc}
     */
    public Writer write(Writer writer) throws IOException {
        writer.append(Boolean.toString(this.booleanValue()));
        return writer;
    }
}
